package compiler.semantic.type;

import compiler.CompilerContext;

import es.uned.lsi.compiler.code.ExecutionEnvironmentIF;
import es.uned.lsi.compiler.semantic.ScopeIF;
import es.uned.lsi.compiler.semantic.type.TypeBase;

/**
 * Class for TypeSimple.
 */

// TODO: Student work
//       Include properties to characterize simple types

public class TypeSimple
    extends TypeBase
{
	
	public enum TIPO { TBOOL, TENT } ;
	
	protected TIPO tipo;
	
	public static TypeSimple TS_BOOL = new TypeSimple (TIPO.TBOOL);
	public static TypeSimple TS_ENT = new TypeSimple (TIPO.TENT);
    
    /**
     * Constructor for TypeSimple.
     * @param scope The declaration scope.
     */
    private TypeSimple (TIPO tipo)
    {
        super (calcScope(), calcNombre(tipo));
        this.tipo = tipo;
        getScope().getTypeTable().addType(getName(), this);
    }
    
    private static String calcNombre(TIPO t) {
		if (t == TIPO.TBOOL)
			return "Boolean";
		else
			return "Integer";
	}

	private static ScopeIF calcScope() {
		return CompilerContext.getScopeManager().getCurrentScope();
	}

	/**
     * Returns the size of the type.
     * @return the size of the type.
     */
    @Override
    public int getSize ()
    {
        ExecutionEnvironmentIF environment = CompilerContext.getExecutionEnvironment ();
        return environment.getTypeSize (this);
    }
}
